(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.user.viewController', viewController);
	viewController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'userService' ];
	function viewController($scope, Constants, layoutConfig, validatorConfig, gridService, authService, userService) {
		var ctrl = this, userInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.user={};
		ctrl.init = function() {
			ctrl.accessRolePermission = {permission : 'accessRole', authorization : authService};
			// init role
			userService.initRole($scope, ctrl);
			ctrl.roleGridOptions.enableRowHeaderSelection = false;
			// init group
			userService.initGroup($scope, ctrl);
			ctrl.groupGridOptions.enableRowHeaderSelection = false;
			// init token
			userService.initToken($scope, ctrl);
			ctrl.tokenGridOptions.enableRowHeaderSelection = false;
			// init user dynaparm
			userService.initDynaParm($scope, ctrl);
			ctrl.selectedPropertyInnerGridOptions.enableRowHeaderSelection = false;
			if(ctrl.availablePropertyInnerGridOptions){
				ctrl.availablePropertyInnerGridOptions.enableRowHeaderSelection = false;
			}
			userService.loadOptions().then(function(userOptions) {
				userService.initOptions(ctrl, userOptions);
				authService.view(userInfo).then(function(response) {
					// init user data
					ctrl.user = response.data || userInfo;
					ctrl.user.userTokens = ctrl.user.userTokens || [];
					ctrl.resetDynaProperties();
				}, angular.noop);
			});
		};
		
	}
})(angular);